list-[id].vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. <template>
  2. <div id="newsList">
  3. <!-- 页面头部 -->
  4. <HomePageHead></HomePageHead>
  5. <!-- 导航栏 -->
  6. <HomePageNavigation></HomePageNavigation>
  7. <!-- 列表页广告一 -->
  8. <HomeTopTen :imgurl="adImg1" v-if="adImg1"></HomeTopTen>
  9. <!-- 资讯列表 -->
  10. <div class="newsList">
  11. <div class="inner">
  12. <div class="innerLeft">
  13. <!-- 面包屑导航 -->
  14. <div class="breadcrumb phone_none">
  15. <div class="inner">
  16. <span class="location">当前位置:</span>
  17. <el-breadcrumb :separator-icon="ArrowRight">
  18. <el-breadcrumb-item>
  19. <NuxtLink to="/">首页</NuxtLink>
  20. </el-breadcrumb-item>
  21. <el-breadcrumb-item v-if="parent_name !=''">
  22. <NuxtLink :to="`/${parent_pinyin}/index.html`"> {{ parent_name }}</NuxtLink>
  23. </el-breadcrumb-item>
  24. <el-breadcrumb-item class="nameBox">{{ name }}</el-breadcrumb-item>
  25. </el-breadcrumb>
  26. </div>
  27. </div>
  28. <div class="breadcrumb_box pc_none">
  29. <span class=" ">当前位置:</span>
  30. <NuxtLink to="/">首页</NuxtLink>
  31. <span class=" " v-if="parent_name !=''">&gt;</span>
  32. <NuxtLink v-if="parent_name !=''" :to="`/${parent_pinyin}/index.html`"> {{ parent_name }}</NuxtLink>
  33. <span class="" >&gt;</span>
  34. {{ name }}
  35. </div>
  36. <ul class="list">
  37. <li v-for="(item, index) in newsList" :key="index">
  38. <NuxtLink :href="getLinkPathDetail(item)" :title="item.alias">
  39. <span class="listTitle">{{ item.title }}</span>
  40. <span class="time">{{ getTime(item.updated_at, 'month', 1) }}</span>
  41. </NuxtLink>
  42. </li>
  43. </ul>
  44. <!-- 分页器 -->
  45. <div class="pagination page_phone_none" v-if="total > 0">
  46. <el-pagination
  47. size="small"
  48. background
  49. layout="prev, pager, next"
  50. :total="total"
  51. class="mt-4"
  52. :page-size="pageSize"
  53. :current-page="pageNum"
  54. prev-text="上一页"
  55. next-text="下一页"
  56. @current-change="changePage"
  57. />
  58. </div>
  59. <div class="pagination page_pc_none" v-if="total > 0">
  60. <el-pagination pager-count="5" size="small" background layout=" pager " :total="total"
  61. class="mt-4" v-model:page-size="pageSize" :current-page="pageNum"
  62. @current-change="changePage" />
  63. </div>
  64. </div>
  65. <div class="innerRight">
  66. <DetailHotNews></DetailHotNews>
  67. <DetailHotNews2></DetailHotNews2>
  68. </div>
  69. </div>
  70. </div>
  71. <!-- 列表页广告二 -->
  72. <HomeTopTen :imgurl="adImg2" v-if="adImg2"></HomeTopTen>
  73. <!-- 页面底部 -->
  74. <HomeFoot1></HomeFoot1>
  75. </div>
  76. </template>
  77. <script setup>
  78. //1.页面必备依赖 start ---------------------------------------->
  79. import { ElBreadcrumb, ElBreadcrumbItem, ElPagination } from 'element-plus';
  80. import { ArrowRight } from '@element-plus/icons-vue';
  81. import { ref, onMounted } from 'vue';
  82. //1.页面必备依赖 end ---------------------------------------->
  83. //2.页面路径 start ---------------------------------------->
  84. const route = useRoute();
  85. let articleId = 0; //获取哪个导航下的列表
  86. //2.1 获得当前的完整路径
  87. const targetSegment = getRoutePath(1);
  88. //通过导航路径反向查询导航id
  89. const getRouteId = await requestDataPromise('/web/getWebsiteRoute', {
  90. method: 'GET',
  91. query: {
  92. 'pinyin': targetSegment,
  93. },
  94. });
  95. if(getRouteId.code == 200){
  96. articleId = getRouteId.data.category_id
  97. }else{
  98. console.log("错误位置:获得页面路径")
  99. }
  100. //2.页面路径 end ---------------------------------------->
  101. //3.页面数据 start ---------------------------------------->
  102. let pageNum = ref(2); //当前页码
  103. pageNum.value = parseInt(route.params.id);//路由中传递的分页页码
  104. let total = ref(1); //总条数
  105. let pageSize = ref(20); //每页条数
  106. //3.1 新闻列表
  107. const newsList = ref([]);
  108. let newslists = async () => {
  109. const listData = await requestDataPromise('/web/getWebsiteArticleList', {
  110. method: 'GET',
  111. query: {
  112. 'page': pageNum.value,
  113. 'pageSize': pageSize.value,
  114. 'catid': articleId
  115. },
  116. });
  117. if (listData.code == 200) {
  118. newsList.value = listData.data.rows;
  119. total.value = listData.data.count;
  120. } else {
  121. console.log("错误位置:获取新闻列表")
  122. }
  123. }
  124. //获得列表
  125. newslists();
  126. //3.2 分页事件
  127. let changePage = (value) => {
  128. console.log("当前页码", value);
  129. navigateTo(`/${targetSegment}/list-${value}.html`)
  130. }
  131. //3.页面数据 end ---------------------------------------->
  132. //4.面包屑 start ---------------------------------------->
  133. const name = ref('')
  134. //4.1 当前频道名称
  135. let getPageName = async () => {
  136. const pageName = await requestDataPromise('/web/getOneWebsiteCategory', {
  137. method: 'GET',
  138. query: {
  139. 'catid': articleId
  140. },
  141. });
  142. if (pageName.code == 200) {
  143. name.value = pageName.data.alias
  144. } else {
  145. console.log("错误位置:获取当前频道名称", pageName.message)
  146. }
  147. }
  148. getPageName();
  149. //4.2 查询是否含有父级导航
  150. const parent_name = ref([]);
  151. const parent_id = ref([]);
  152. const parent_pinyin = ref("");
  153. let getParentNav = async () => {
  154. const listData = await requestDataPromise('/web/getOneWebsiteCategory', {
  155. method: 'GET',
  156. query: {
  157. 'catid': articleId
  158. },
  159. });
  160. if (listData.code == 200) {
  161. parent_name.value = listData.data.parent_name;
  162. parent_id.value = listData.data.parent_id;
  163. parent_pinyin.value = listData.data.parent_pinyin;
  164. } else {
  165. console.log("错误位置:查询父级导航信息")
  166. }
  167. getSecondNav();
  168. }
  169. getParentNav();
  170. //4.3 获取二级栏目列表
  171. const secondNav = ref([]);
  172. let getSecondNav = async () => {
  173. const listData = await requestDataPromise('/web/getWebsiteModelCategory', {
  174. method: 'GET',
  175. query: {
  176. 'placeid': 1,
  177. 'pid': parent_id.value,
  178. 'num': 8,
  179. },
  180. });
  181. console.log('listData', listData);
  182. if (listData.code == 200) {
  183. secondNav.value = listData.data
  184. } else {
  185. console.log("错误位置:获得二级栏目列表")
  186. }
  187. }
  188. //4.面包屑 end ---------------------------------------->
  189. //5.设置seo信息 start---------------------------------------->
  190. const setData = await requestDataPromise('/web/getWebsiteCategoryHead', {
  191. method: 'GET',
  192. query: {
  193. 'catid': articleId
  194. },
  195. });
  196. if (setData.code == 200) {
  197. let seoTitle = setData.data.seo_title;
  198. let seoDescription = setData.data.seo_description;
  199. let seoKeywords = setData.data.seo_keywords;
  200. let seoSuffix = setData.data.suffix;
  201. let seoName = setData.data.website_name;
  202. useSeoMeta({
  203. title: seoTitle + "_" + seoName + "_" + seoSuffix,
  204. meta: [
  205. { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix , tagPriority: 10 },
  206. { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix , tagPriority: 10 },
  207. { name: 'viewport', content: 'width=device-width,initial-scale=1,user-scalable=no',tagPriority: 10 }
  208. ]
  209. });
  210. } else {
  211. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  212. // console.log("错误位置:设置列表页面SEO数据")
  213. // console.log("后端错误反馈:", setData.message)
  214. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  215. }
  216. //5.设置seo信息 end---------------------------------------->
  217. //6.广告 start---------------------------------------->
  218. let adImg1 = ref({});
  219. let adImg2 = ref({});
  220. onMounted(async () => {
  221. //从客户端获取行政职能部门 加快打开速度
  222. const { $webUrl, $CwebUrl } = useNuxtApp();
  223. //广告1
  224. let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=nmgw_list_0001`
  225. const responseAd1 = await fetch(url, {
  226. headers: {
  227. 'Content-Type': 'application/json',
  228. 'Userurl': $CwebUrl,
  229. 'Origin': $CwebUrl
  230. }
  231. });
  232. const resultAd1 = await responseAd1.json();
  233. adImg1.value = resultAd1.data[0];
  234. //广告2
  235. let url2 = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=nmgw_list_0002`
  236. const responseAd2 = await fetch(url2, {
  237. headers: {
  238. 'Content-Type': 'application/json',
  239. 'Userurl': $CwebUrl,
  240. 'Origin': $CwebUrl
  241. }
  242. });
  243. const resultAd2 = await responseAd2.json();
  244. adImg2.value = resultAd2.data[0];
  245. })
  246. //6.广告 end---------------------------------------->
  247. </script>
  248. <style lang="less" scoped>
  249. @import url('@/assets/css/list.less');
  250. </style>
  251. <style lang="less" scoped>
  252. @media screen and (min-width:801px) {
  253. /*pc*/
  254. .page_pc_none {
  255. display: none !important;
  256. }
  257. .pc_none {
  258. display: none;
  259. }
  260. }
  261. @media screen and (max-width:800px) {
  262. /*ipad_phone*/
  263. .newsList .inner {
  264. width: 92%;
  265. margin: 0px auto 0px;
  266. }
  267. .newsList .inner .innerLeft {
  268. width: 100%;
  269. float: none;
  270. }
  271. .newsList .inner .innerLeft {
  272. width: 100%;
  273. float: none;
  274. margin: 0px auto;
  275. }
  276. .newsList .inner .innerLeft .list li .time {
  277. display: none !important;
  278. }
  279. .newsList .inner .innerLeft .list li {
  280. display: block;
  281. width: 100%;
  282. padding: 14px 0 !important;
  283. }
  284. .newsList .inner .innerLeft .list li .listTitle {
  285. font-size: 16px;
  286. font-weight: normal !important;
  287. }
  288. .newsList .inner .innerLeft>.pagination {
  289. width: 100%;
  290. }
  291. .newsList .inner .innerLeft>.pagination .el-pagination.is-background .el-pager li {
  292. margin: 0px 4px;
  293. }
  294. .newsList .inner .innerLeft .list {
  295. margin-bottom: 10px;
  296. border-top: solid 1px #489d97;
  297. min-height:493px;
  298. }
  299. .breadcrumb_box {
  300. height: 22px;
  301. width: 100%;
  302. margin: 10px auto;
  303. word-break: keep-all;
  304. white-space: nowrap;
  305. overflow: hidden;
  306. text-overflow: ellipsis;
  307. font-size: 14px;
  308. color: #666;
  309. * {
  310. font-size: 14px;
  311. display: inline;
  312. color: #666;
  313. line-height: 22px;
  314. height: 22px;
  315. margin-right: 5px;
  316. }
  317. }
  318. .newsList .inner .innerLeft>.pagination /deep/.el-pagination.is-background .el-pager li {
  319. margin: 0px 4px;
  320. }
  321. .newsList {
  322. margin-bottom: 23px;
  323. }
  324. .page_phone_none {
  325. display: none !important;
  326. }
  327. .innerRight {
  328. display: none;
  329. }
  330. .phone_none {
  331. display: none;
  332. }
  333. }
  334. </style>